<template>
	<view class="container">
		<view class="main">
		 <view @click="handleBindPay(0)">
				<view>
					<image src="/static/icon1/26.png" mode="aspectFill"></image>
					<text>支付宝</text>
				</view>
				<view>
					<text>{{ alipayAccount ? alipayAccount.replace(alipayAccount.slice(3, 7), '****') : '去绑定'  }}</text>
					<image src="/static/icon1/17.png" mode="aspectFill"></image>
				</view>
			</view>
			
			<view @click="handleBindPay(1)">
				<view>
					<image src="/static/icon1/05.png" mode="aspectFill"></image>
					<text>微信</text>
				</view>
				<view>
					<text>{{ wechatAccount ? wechatAccount.replace(wechatAccount.slice(1, 4), '***') : '去绑定'  }}</text>
					<image src="/static/icon1/17.png" mode="aspectFill"></image>
				</view>
			</view>
			
			<view @click="handleBindPay(2)">
				<view>
					<image src="/static/icon1/27.png" mode="aspectFill"></image>
					<text>银行卡</text>
				</view>
				<view>
					<text>{{ bankAccount ? bankAccount.replace(bankAccount.slice(3, bankAccount.length-4), '**********') : '去绑定'  }}</text>
					<image src="/static/icon1/17.png" mode="aspectFill"></image>
				</view>
			</view>
			
			
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				alipayAccount: '',
				bankAccount: '',
				wechatAccount: '',
			}
		},
		methods: {
			//跳转页面，绑定银行卡或支付宝
			handleBindPay (flag) {
				// 0 支付宝,2银行卡，1微信
				if(flag == 0) {
					uni.navigateTo({ url: '/pages/alipay/alipay' })
				}else if(flag == 1){
					uni.navigateTo({ url: '/pages/wechat/wechat' })
				}else if(flag == 2){
					uni.navigateTo({ url: '/pages/bank-card/bank-card' })
				}
			},
			
			
			
			// 获取已绑定的账号
			async query_bind_user_bank () {
				let res = await this.$fetch(this.$api.query_bind_user_bank, {}, 'POST')
				if (res.code) return uni.showToast({ title: res.msg, icon: 'none' })
				console.log('我的账户', res.data)
				res.data.forEach(item=> {
					if(item.type === 0) {
						this.alipayAccount = item.account
					}else if(item.type === 1){
						this.wechatAccount = item.account
					}else if(item.type === 2){
						this.bankAccount = item.account
					}
				})
			},
		},
		onShow() {
			this.query_bind_user_bank()
		}
	}
</script>

<style lang="less">
.container {
	// border: 1px solid #000000;
	& > .main {
		margin-top: 30rpx;
		background-color: #FFFFFF;
		& > view {
			position: relative;
			//height: 40rpx;
			padding: 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			& > view:first-child {
				display: flex;
				align-items: center;
				// border: 1px solid #000000;
				& > image {
					width: 40rpx;
					height: 40rpx;
					margin-right: 20rpx;
				}
			}
			& > view:last-child {
				// border: 1px solid #000000;
				display: flex;
				align-items: center;
				& > text {
					margin-right: 30rpx;
					color: rgba(64,33,16,0.50);
				}
				& > image {
					width: 16rpx;
					height: 26rpx;
				}
			}
			
			&::before {
				content: "";
				position: absolute;
				top: 100rpx;
				width: 720rpx;
				height: 2rpx;
				background: #F2F2F2;
				border-radius: 1px;
			}
		}
	}
	
}
</style>
